mini.parse();
var modelName2=parent.mainTab();
modelName2=modelName2.data;
console.log(modelName2);
var grid=mini.get("datagrid1");
//页面自动加载
$(function () {
	request();//加载请求
})
var modelId = localStorage.getItem("modelId");
modelId = JSON.parse(modelId);
function request(){
	$.ajax({
		url: ajaxUrl + "/rule/showListByModelId.do",
		type: "post",
		data:{modelId:modelId},
		success: function (data) {
			console.log(data);
			grid.setData(data.data);
		},
		error: function (data) {
		}
	});
}
//新增页面
function add(){
	localStorage.setItem("modelId",JSON.stringify(modelId));
	var item = {
		iconCls: "fa fa-desktop",
		// id: formId,
		text: "规则设计",
		url: "../pages/reference/addRefRule.html"
	};
	parent.activeTab(item);//与父页面通信
}
//编辑页面
function edit() {
	var row=grid.getSelected();
	console.log(row);
	var ruled2=mini.clone(row.ruleId);
	console.log(ruled2);
	var modelId=row.modelId;
	if (row!=undefined) {
		localStorage.setItem("modelName",JSON.stringify(modelName2))
		localStorage.setItem("editdata", JSON.stringify(row));
		var edit_data = localStorage.getItem("editdata");
		console.log(edit_data);
		console.log(modelId);
		$.ajax({
			url:ajaxUrl + "/rule/findByRuleIdToUpdate.do",
			type:"post",
			data:{
				ruleId:row.ruleId
			},
			success:function (data) {
				console.log(data);
				var	 data99=mini.clone(data)
				console.log(data99);
				data99.ruleId=ruled2;
				console.log(data99);
				var item = {
					iconCls: "fa fa-desktop",
					// id: formId,
					text: "规则设计",
					url: "../pages/reference/editRefRule.html",
					data:data99
				};
				parent.activeTab(item);//与父页面通信
			},
			error:function (data) {
					console.log("失败")
			}
		})

	}else {
		mini.alert("请您选中一条记录进行修改");
	}
}
//删除
function remove() {
	var selected = grid.getSelected();
	if (selected!=undefined) {
		$.ajax({
			url: ajaxUrl + "/rule/deleteRule.do",
			type: "post",
			data: {ruleId: selected.ruleId},
			success: function (data) {
				console.log(data);
				request();
			},
			error: function (data) {
			}
		});
	}else {
		mini.alert("请您选择一条");
	}
}
